/***************************************************************************
 //* Foxit Software Inc.
 //* Copyright(C) 2005-2012, all rights reserved.
 //*
 //* The following code is copyrighted and contains proprietary information
 //* and trade secrets of Foxit Software Inc.                                                      *
 ***************************************************************************/

/**
 * 缩略图显示
 */
define(function (require, exports, module) {
    var CPDF_PageThumb = require('./PDFThumb');
    var ProgressiveViewerGenerator = require('../../PDFView/ProgressiveViewerGenerator');
    var Config = WebPDF.Config;
    WebPDF.PDFView.CPDF_PageThumbsView = function (pdfDoc, mainFrameID, readerApp) {
        if (!pdfDoc)
            $.error("pPDFDoc is null!");
        var _thumbList = {},            
            _thumbsViewContainerID = mainFrameID + "_ThumbsViewContainer",
            _jqThumbsViewContainer = null,
            mainFrameID = mainFrameID,
            _readerApp = readerApp,
        //视口宽度;
            _thumbsViewWidth = 0,
        //视口高度;
            _thumbsViewHeight = 0,
        //处于显示区域的页面;
            _visiblePageRange = { begin: 0, end: 0, current: 0 },
        //滚动条api;
            _scrollApi = null,
        //当前页面索引;
            _curPageIndex = 0,
        //当前用于焦点的页面;
            _curSelectedPage = -1,
        //当前处于选中状态的页面;
            _thumbFocusPage = -1,
            _pdfDoc = pdfDoc,
            _progressiveViewerGenerator = null,
            _self = this;
        
        var _blankImg = "";
        //var _thumbImgLeftOffset = WebPDF.PDFView.STANDARD_THUMB_CONTAINER_WIDTH - WebPDF.PDFView.STANDARD_THUMB_WIDTH,
        //    _thumbImgTopOffset = WebPDF.PDFView.STANDARD_THUMB_CONTAINER_HEIGHT - WebPDF.PDFView.STANDARD_THUMB_HEIGHT;
        var _documentScrollTimeout = null;


        //判断页面是否处于显示区域;
        function _isPageVisible(pageIndex) {
            return pageIndex >= _visiblePageRange.begin && pageIndex <= _visiblePageRange.end;
        }

        /**
         * Get id of container for thumbnails view.
         * @returns {string} id of container for thumbnails view.
         */
        this.getThumbsViewContainerID = function () {
            return _thumbsViewContainerID;
        };
        /**
         * Get id of thumbnail
         * @param pageIndex index of thumb
         * @returns {string} id of container for thumbnails view.
         */
        this.getPageViewContainerID = function (pageIndex) {
            return _thumbsViewContainerID + "_ThumbContainer_" + pageIndex.toString();
        };
        //根据页面索引，生成对应页面背景图ID;
        this.getPageBackgroundImgID = function (pageIndex) {
            return _thumbsViewContainerID + "_BG_" + pageIndex.toString();
        };
        //根据页面索引，生成对应页面Wrap ID;
        this.getWrapPageID = function (pageIndex) {
            return _thumbsViewContainerID + "_Wrap_" + pageIndex.toString();
        };
        //根据页面索引，生成对应页面Loading 图标 ID;
        this.getPageLoaderImageID = function (pageIndex) {
            return _thumbsViewContainerID + "_Loader_" + pageIndex.toString();
        };
        this.getThumbPageNumberID = function (pageIndex) {
            return _thumbsViewContainerID + "_PageNum_" + pageIndex.toString();
        };

        this.setThumbsViewWidth = function (width) {
            _thumbsViewWidth = width;
        };
        this.getPageViewsViewWidth = function () {
            return _thumbsViewWidth;
        };
        this.setThumbsViewHeight = function (height) {
            _thumbsViewHeight = height;
        };
        this.getPageViewsViewHeight = function () {
            return _thumbsViewHeight;
        };

        //获取页数
        this.getPageCount = function () {
            return _pdfDoc.getPageCount();
        };

        this.getPageView = function (pageIndex) {
            return _thumbList[pageIndex];
        };

        //初始化DocView;
        this.init = function () {
            _progressiveViewerGenerator = new ProgressiveViewerGenerator(_self,_thumbsViewContainerID);
            var pageCnt = _pdfDoc.getPageCount();
            for (var i = 0; i < pageCnt; i++) {
                _thumbList[i] = new CPDF_PageThumb(_pdfDoc.getPage(i), _self, _thumbsViewContainerID);
            }
            var thumbsViewHtml = _createThumbsViewHtml();
            var jqMainFrameObj = $("#" + this.mainFrameID);
            jqMainFrameObj.append(thumbsViewHtml);
            _jqThumbsViewContainer = $("#" + _thumbsViewContainerID);
            var jqThumbsViewHeight = _jqThumbsViewContainer.height();
            _jqThumbsViewContainer.height(jqThumbsViewHeight - (_jqThumbsViewContainer.outerHeight() - jqThumbsViewHeight));
            _progressiveViewerGenerator.createPages(0);
            _self.initializeScrollBar();
            _bindScrollEvent();
            _onPageScroll();
        };

        /**
         * Bind scroll events.
         * @private
         */
        function _bindScrollEvent() {
            _jqThumbsViewContainer.scroll(_onPageScroll);
        }
        /**
         * Unbind scroll events.
         * @private
         */
        function _unBindScrollEvent() {
            _jqThumbsViewContainer.off("scroll");
        }

        /**
         * Insert html of thumbnails to DOM.
         * @param startIndex start page index
         * @param endIndex end page index
         * @param insertAfterPageIndex if this parameter set to -1, new html will be insert after last page which has been create.
         *      otherwise new html will be insert after this page.
         */
        this.createPagesView = function (startIndex, endIndex, insertAfterPageIndex) {
            var totalHtml = "";
            var pageHtml;
            for (var i = startIndex; i <= endIndex; i++) {
                pageHtml = _createThumbHtml(i);
                totalHtml += pageHtml;
                _self.getPageView(i).setContentCreatedState(true);
            }

            var insertPageID = _self.getPageViewContainerID(insertAfterPageIndex);
            if (insertAfterPageIndex === -1){
                _jqThumbsViewContainer.append(totalHtml);
            }
            else {
                $(totalHtml).insertAfter($("#" + insertPageID));
            }
            return true;
        };

        /**
         * Create html for a thumbnail
         * @param pageIndex page index
         * @returns {string} html for a thumbnail
         * @private
         */
        function _createThumbHtml(pageIndex) {
            var thumbView = _self.getPageView(pageIndex);
            if (!thumbView)
                return "";
            var pdfPage = thumbView.getPDFPage();
            var thumbWidth = WebPDF.PDFView.STANDARD_THUMB_WIDTH,
                thumbHeight = WebPDF.PDFView.STANDARD_THUMB_HEIGHT,
                thumbContainerWidth = WebPDF.PDFView.STANDARD_THUMB_CONTAINER_WIDTH,
                thumbContainerHeight = WebPDF.PDFView.STANDARD_THUMB_CONTAINER_HEIGHT,
                thumbContainerStr = "margin-left:10px;",
                pageNumberStyleStr = "",
                thumbImageClass = "border fwr-thumb-image",
                thumbWrapPageClass = "border",
                thumbPageClass = "";
            if (WebPDF.Environment.mobile) {
                thumbWidth = WebPDF.PDFView.STANDARD_THUMB_WIDTH_MOBILE;
                thumbHeight = WebPDF.PDFView.STANDARD_THUMB_HEIGHT_MOBILE;
                thumbContainerWidth = thumbWidth;
                thumbContainerHeight = thumbHeight;
                thumbContainerStr = "margin-left:46px;margin-top:15px;";
                pageNumberStyleStr = "font-size:20px;";
                thumbImageClass = "";
                thumbWrapPageClass = "";
                thumbPageClass = "fwr-thumb-page-wap";
            }

            var fZoomX = parseFloat(pdfPage.getPageWidth() / thumbWidth);
            var fZoomY = parseFloat(pdfPage.getPageHeight() / thumbHeight);
            thumbView.setPageViewWidth(thumbWidth);
            thumbView.setPageViewHeight(thumbHeight);
            var fZoom = fZoomX > fZoomY ? fZoomX : fZoomY;
            var w, h, l, t;
            w = parseFloat(pdfPage.getPageWidth() / fZoom);
            h = parseFloat(pdfPage.getPageHeight() / fZoom);
            l = -w / 2;
            t = -h / 2;
            if (!WebPDF.Environment.mobile) {
                t = t - 10;
            }
            var loadingClass = "fwr-page-loading";
            var dimensions = "height:" + h + "px;width:" + w + "px;" + "left:50%;position:absolute;margin-left:" + l
                + "px;top:50%;margin-top:" + t + "px;";
            var html = "<div id='" + _self.getPageViewContainerID(pageIndex) +
                "' class='fwr-display-inline-block fwr-thumb-page " + thumbPageClass + "' style='position:relative;display:inline-block;" +
                thumbContainerStr + "height:" + thumbContainerHeight + "px;width:" + thumbContainerWidth + "px;'>";
            html += "<div id='" + _self.getWrapPageID(pageIndex)
                + "' class='thumbimage " + thumbWrapPageClass + "' style='background-color:white;cursor:pointer;" + dimensions + "' page-index='" + pageIndex + "'></div>"
                + "<img alt='' src='" + _blankImg + "' id='" + _self.getPageBackgroundImgID(pageIndex)
                + "' class='fwr-hidden thumbimage " + thumbImageClass + "' style='" + dimensions + ";background-size:cover;' page-index='"
                + pageIndex + "'/>"
                + "<div id='" + _self.getPageLoaderImageID(pageIndex) + "' class='" + loadingClass + "' />";
            html += "<div class='fwr-page-number' style='width:20px;position:absolute;bottom:1px;left:50%;"
                + pageNumberStyleStr + "text-align:center;margin-left:-10px'><span id='"
                + _self.getThumbPageNumberID(pageIndex) + "'>" + (pageIndex + 1) + "</span></div>";
            html += "</div>";
            var fOffsetTop = (thumbContainerHeight - h) / 2 - 10;
            thumbView.setThumbImgOffsetTop(fOffsetTop);
            return html;
        }

        /**
         * Create html for thumbnails view.
         * @returns {string} html for thumbnails view.
         * @private
         */
        function _createThumbsViewHtml() {
            var html = "";
            var styleStr = "";
            if (WebPDF.Environment.mobile) {
                styleStr = "padding-top:0;";
            }
            switch(_readerApp.getOptions().scrollBarType) {
                case WebPDF.PDFView.ScrollBarType.CUSTOM_SCROLL_BAR:
                {
                    html = "<div id='" + _self.getThumbsViewContainerID() +
                        "' class='fwr-pages' style='height:100%;width:100%;overflow-x: hidden;overflow-y:hidden;"
                        + styleStr + "'></div>";
                }break;
                case WebPDF.PDFView.ScrollBarType.NATIVE_SCROLL_BAR:
                {
                    html = "<div id='" + _self.getThumbsViewContainerID() +
                        "' class='fwr-pages' style='height:100%;width:100%;overflow-x: hidden;overflow-y:auto;position: relative;"
                        + styleStr + "'></div>";
                }break;
                default: {
                    $.error("Unsupported type of scroll bar.");
                }break;
            }
            return html;
        }

        /**
         * Init touch events.
         * @private
         */
        function _initTouchEvent() {
            var oldX = 0;
            var oldY = 0;
            var endX = 0, endY = 0;
            var bMovePage = false;
            _jqThumbsViewContainer.off('touchstart touchmove touchend').on(
                'touchstart',
                function (e) {
                    if (e.originalEvent.touches != null && e.originalEvent.touches.length != 1)
                        return;
                    var touch = e.originalEvent.touches[0];
                    var elem = touch.target;
                    if(WebPDF.Common.isElemInteractive(elem)){
                        return true;
                    }
                    bMovePage = true;
                    oldX = touch.pageX;
                    oldY = touch.pageY;
                }
            ).on(
                'touchmove',
                function (e) {
                    if (e.originalEvent.touches != null && e.originalEvent.touches.length != 1)
                        return;
                    var touch = e.originalEvent.touches[0];
                    var elem = touch.target;
                    if(WebPDF.Common.isElemInteractive(elem)){
                        return true;
                    }
                    endX = touch.pageX;
                    endY = touch.pageY;
                    if (!bMovePage) {
                        return;
                    }
                    e.preventDefault();
                    _scrollApi.scrollBy(oldX - endX, oldY - endY);
                }
            ).on(
                'touchend',
                function () {
                    bMovePage = false;
                }
            );
        }

        /**
         * Initialize scroll bar
         * @returns {Object} scroll api
         */
        this.initializeScrollBar = function () {
            if (_scrollApi != null)
                return _scrollApi;
            var settings = {
                showArrows: false,
                animateScroll: false,
                initTouchScreen: true,
                disableHorizontalScroll: true
            };
            var scrollApiElem = '';
            switch(_readerApp.getOptions().scrollBarType) {
                case WebPDF.PDFView.ScrollBarType.CUSTOM_SCROLL_BAR:
                {
                    scrollApiElem = _jqThumbsViewContainer.fwrJScrollPane(settings);
                }break;
                case WebPDF.PDFView.ScrollBarType.NATIVE_SCROLL_BAR:
                {
                    scrollApiElem = _jqThumbsViewContainer.WebPDFNativeScroll(settings);
                    if (WebPDF.Environment.mobile) {
                        _initTouchEvent();
                    }
                }break;
                default: {
                    $.error("Unsupported type of scroll bar.");
                }break;
            }
            _scrollApi = scrollApiElem.data('jsp');
            return _scrollApi;
        };

        /**
         * Reinitialize scroll bar.
         */
        this.reinitializeScrollBar = function () {
            if (_scrollApi == null)
                $.error('Scroll Api is null!');
            _scrollApi.reinitialise(
                {
                    showArrows: false,
                    animateScroll: false
                }
            );
        };
        /**
         * Get scroll api
         * @returns {Object} scroll api.
         */
        this.getScrollApi = function () {
            return _scrollApi;
        };

        /**
         * Get range of visible pages.
         * @returns {{begin: number, end: number, current: number}}
         */
        this.getVisiblePageRange = function () {
            return _visiblePageRange;
        };

        this.countVisiblePageRange = function () {
        	if($("#" + _thumbsViewContainerID).is(":visible")) {
        		_visiblePageRange = _progressiveViewerGenerator.countVisiblePageRange();
            }
        	else{
        		_visiblePageRange = {begin:0, end:0, current:0};
        	}
            return _visiblePageRange;
        };

        this.getScale = function(){
            return 1;
        };

        this.setScale = function(scale){
        };

        /**
         * 获取页面相对于视口区域的Y轴偏移
         * @param thumbIndex 页面索引
         * @returns {number} 偏移量
         * @private
         */
        function _getPageViewOffsetDocY(thumbIndex) {
            var pThumbView = _self.getPageView(thumbIndex);
            if (!pThumbView.isContentCreated())
                return 0;
            var thumbOffset = $("#" + pThumbView.getPageViewContainerID()).offset();
            var thumbsViewOffset = _jqThumbsViewContainer.offset();
            return thumbsViewOffset.top - thumbOffset.top;
        }

        /**
         * Page scroll event handler.
         * @private
         */
        function _onPageScroll() {
            var range = _self.countVisiblePageRange();
            var lastVisiblePageIndex = range.end;
            var firstVisiblePageIndex = range.begin;
            var pageCount = _self.getPageCount();
            if (_scrollApi != null) {
                var offsetX = _scrollApi.getContentPositionX();
                var isDocViewContentChanged = false;
                var offsetY = _getPageViewOffsetDocY(_curPageIndex);
                if (firstVisiblePageIndex >= 1 && !_self.getPageView(lastVisiblePageIndex - 1).isContentCreated()) {
                    isDocViewContentChanged = _progressiveViewerGenerator.createPages(firstVisiblePageIndex - 1);
                }
                if (lastVisiblePageIndex < pageCount - 1 && !_self.getPageView(lastVisiblePageIndex + 1).isContentCreated()) {
                    isDocViewContentChanged |= _progressiveViewerGenerator.createPages(lastVisiblePageIndex + 1);
                }
                if (isDocViewContentChanged) {
                    _scrollApi.scrollToX(offsetX);
                }
                _progressiveViewerGenerator.progressiveUpdatePageDimension(_curPageIndex, firstVisiblePageIndex, lastVisiblePageIndex,
                    offsetY, true, true);
                _progressiveViewerGenerator.createAdjacentPage(_curPageIndex, offsetY);
            }

            range = _self.countVisiblePageRange();
            _curPageIndex = range.current;

            // Resets timeout to prevent page load per scroll event
            if (_documentScrollTimeout) {
                clearTimeout(_documentScrollTimeout);
            }
            _documentScrollTimeout = setTimeout(function () {
            	if($("#" + _thumbsViewContainerID).is(":visible"))
                {
            		_loadPages(range);
                }
            }, 200);
        }

        /**
         * Load pages.
         * @param range range of pages to load.
         * @private
         */
        function _loadPages(range) {
            var pageViewRender = _readerApp.getMainView().getDocView().getPageViewRender();
            for (var i = range.begin; i <= range.end; i++) {
                var thumb = _self.getPageView(i);
                pageViewRender.renderPage(thumb, WebPDF.Config.requestRetryCount);
            }
        }

        /**
         * 跳转到对应页面.;
         * @param [pageIndex] 页面索引;
         * @param [offsetX] 相对要跳转页面的左边距离;
         * @param [offsetY] 相对要跳转页面的顶部距离;
         */
        this.goToPage = function (pageIndex, offsetX, offsetY) {
            if (!_scrollApi){
                return;
            }
            _unBindScrollEvent();
            offsetY = offsetY ? offsetY : 0;
            if (offsetX === null){
                offsetX = _scrollApi.getContentPositionX();
            }
            var pageCount = _self.getPageCount();
            if (pageIndex < 0 || pageIndex >= pageCount) {
                return;
            }
            var maxNewPagesPerTime = WebPDF.Config.maxNewPagesPerTime;
            if (maxNewPagesPerTime === -1) {
                maxNewPagesPerTime = pageCount;
            }
            if ((pageIndex + 1) % maxNewPagesPerTime === 0) {
                _progressiveViewerGenerator.createPages(pageIndex + 1);
                _progressiveViewerGenerator.createPages(pageIndex);
            }
            else {
                var page2Create = pageIndex + 1;
                if (page2Create >= pageCount){
                    page2Create = pageCount - 1;
                }
                _progressiveViewerGenerator.createPages(page2Create);
            }
            _curPageIndex = pageIndex;
            _scrollApi.scrollToElement("#" + _self.getPageView(pageIndex).getPageViewContainerID(), true, false, offsetY);
            _scrollApi.scrollToX(offsetX);
            if (_progressiveViewerGenerator.progressiveUpdatePageDimension(pageIndex, _curPageIndex, _curPageIndex, offsetY, true, true)) {
                _self.countVisiblePageRange();
            }

            _progressiveViewerGenerator.createAdjacentPage(pageIndex, offsetY);
            var newVisibleRange = _self.getVisiblePageRange();
            _curPageIndex = newVisibleRange.current;
            _loadPages(newVisibleRange);

            _bindScrollEvent();
            return true;
        };

        /**
         * Go to next page.
         */
        this.goToNextPage = function () {
            if (_curPageIndex >= _self.getPageCount()) {
                return;
            }
            _self.goToPage(_curPageIndex + 1);
        };
        /**
         * Go to previous page.
         */
        this.goToPrevPage = function () {
            if (_curPageIndex <= 0) {
                return;
            }
            _self.goToPage(_curPageIndex - 1);
        };

        /**
         * 响应视口大小改变事件
         * @param newWidth 新的视口宽度
         * @param newHeight 新的视口高度
         */
        this.onSize = function (newWidth, newHeight) {
            _unBindScrollEvent();
            //这里需要将height减去边距和padding
            newHeight = newHeight - (_jqThumbsViewContainer.outerHeight() - _jqThumbsViewContainer.height());
            _self.setThumbsViewWidth(newWidth);
            _self.setThumbsViewHeight(newHeight);
            _jqThumbsViewContainer.css({ width: newWidth, height: newHeight });
            var curDocViewPageIndex = _readerApp.getDocView().getCurPageIndex();
            if(_curPageIndex != curDocViewPageIndex){
                _self.goToPage(curDocViewPageIndex);
            }
            var oldPage = curDocViewPageIndex;
            _self.reinitializeScrollBar();
            _onPageScroll();
            _bindScrollEvent();
            //保持原来的页数;
            _scrollApi.scrollToElement("#" + _self.getPageView(oldPage).getPageViewContainerID(), true, false);
            _self.setThumbFocus(oldPage);
        };

        /**
         * Set selected page
         * @param pageIndex selected page index
         */
        this.setSelectedPage = function (pageIndex) {
            var pageCount = _self.getPageCount();
            if (pageIndex < 0 || pageIndex >= pageCount || _curSelectedPage === pageIndex) {
                return;
            }
            var bPageLoadErr, jqThumbView, jqWrap;
            if (_curSelectedPage !== -1) {
                var thumb = _self.getPageView(_curSelectedPage);
                jqThumbView = $("#" + thumb.getPageViewContainerID());
                if (!WebPDF.Environment.mobile) {
                    jqThumbView.removeClass("fwr-thumb-image-selected");
                }
                bPageLoadErr = thumb.isPageLoadError();
                if (bPageLoadErr) {
                    jqWrap = $("#" + thumb.getWrapPageID());
                    jqWrap.css({ "margin-left": -jqWrap.outerWidth() / 2 });
                }
                else {
                    var jqThumbBGImg = $("#" + thumb.getPageBackgroundImgID());
                    jqThumbBGImg.css({ "margin-left": -jqThumbBGImg.outerWidth() / 2 });
                }
            }
            var newThumb = _self.getPageView(pageIndex);
            bPageLoadErr = newThumb.isPageLoadError();
            if (bPageLoadErr) {
                jqWrap = $("#" + newThumb.getWrapPageID());
                jqWrap.css({ "margin-left": -jqWrap.outerWidth() / 2 });
            }
            else {
                var jqNewThumbBGImg = $("#" + newThumb.getPageBackgroundImgID());
                jqNewThumbBGImg.css({ "margin-left": -jqNewThumbBGImg.outerWidth() / 2 });
            }
            jqThumbView = $("#" + newThumb.getPageViewContainerID());
            if (!WebPDF.Environment.mobile) {
                jqThumbView.addClass("fwr-thumb-image-selected");
            }
            _curSelectedPage = pageIndex;
        };

        //设置当前处于选中状态的页面；
        this.setThumbFocus = function (pageIndex) {
            var pageCount = _self.getPageCount();
            if (pageIndex < 0 || pageIndex >= pageCount || _thumbFocusPage === pageIndex) {
                return;
            }
            var bPageLoadErr, outerWidth, jqWrap;
            if (_thumbFocusPage !== -1) {
                var thumb = _self.getPageView(_thumbFocusPage);
                bPageLoadErr = thumb.isPageLoadError();
                if (!WebPDF.Environment.mobile) {
                    if (bPageLoadErr) {
                        jqWrap = $("#" + thumb.getWrapPageID());
                        jqWrap.removeClass("fwr-thumb-image-emphasized");
                        outerWidth = jqWrap.outerWidth();
                        if (outerWidth > 0){
                            jqWrap.css({ "margin-left": -outerWidth / 2 });
                        }
                    }
                    else {
                        var jqThumbBGImg = $("#" + thumb.getPageBackgroundImgID());
                        jqThumbBGImg.removeClass("fwr-thumb-image-emphasized");
                        jqThumbBGImg.addClass("fwr-thumb-image");
                        outerWidth = jqThumbBGImg.outerWidth();
                        if (outerWidth > 0)
                            jqThumbBGImg.css({ "margin-left": -outerWidth / 2 });
                    }

                    $("#" + thumb.getThumbPageNumberID()).removeClass("fwr-page-number-focus");
                } else {
                    var jqViewContainer = $("#" + thumb.getPageViewContainerID());
                    jqViewContainer.removeClass("fwr-thumb-page-emphasized-wap").addClass("fwr-thumb-page-wap");
                }
            }
            _self.countVisiblePageRange();
            if (!_isPageVisible(pageIndex)) {
                _self.goToPage(pageIndex, 0, 0);
                _progressiveViewerGenerator.createAdjacentPage(pageIndex, 0);
            }
            var newThumb = _self.getPageView(pageIndex);
            bPageLoadErr = newThumb.isPageLoadError();
            if (!WebPDF.Environment.mobile) {
                if (bPageLoadErr) {
                    jqWrap = $("#" + newThumb.getWrapPageID());
                    jqWrap.addClass("fwr-thumb-image-emphasized");
                }
                else {
                    var jqNewThumbBGImg = $("#" + newThumb.getPageBackgroundImgID());
                    jqNewThumbBGImg.addClass("fwr-thumb-image-emphasized");
                    jqNewThumbBGImg.removeClass("fwr-thumb-image");
                }

                $("#" + newThumb.getThumbPageNumberID()).addClass("fwr-page-number-focus");
            } else {
                var jqViewContainer = $("#" + newThumb.getPageViewContainerID());
                jqViewContainer.removeClass("fwr-thumb-page-wap").addClass("fwr-thumb-page-emphasized-wap");
            }
            _onPageScroll();
            _thumbFocusPage = pageIndex;
        };
    };

    return WebPDF.PDFView.CPDF_PageThumbsView;
});